package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListServiceImpl implements BlackListService {


    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 分页查询黑名单
     * @param pageNumber
     * @param pageSize
     * @param userId
     * @return
     */
    @Override
    public PageBeanVo findBlackUserByUserId(Integer pageNumber, Integer pageSize, Long userId) {
        //1.开启分页
        IPage<UserInfo> iPage = new Page(pageNumber , pageSize);
        //2.查询数据  IPage<UserInfo> -> mybatis提供的分页对象
        iPage = blackListMapper.findBlackListByUserId(iPage, userId);

        //3.构建返回值
        return new PageBeanVo(pageNumber , pageSize , iPage.getTotal() ,iPage.getRecords() );
    }

    /**
     * 根据用户id和黑名单用户id删除数据
     * @param userId
     * @param blackUserId
     */
    @Override
    public void deleteBlackUser(Long userId, Long blackUserId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id" , userId);
        queryWrapper.eq("black_user_id" , blackUserId);
        blackListMapper.delete(queryWrapper);
    }
}
